package com.soft.base.util;


/**
 * class
 *
 * @author user
 * @date 2020/06/05
 */
public class OSUtil {
    private static String OS = System.getProperty("os.name").toLowerCase();

    private static OSUtil instance = new OSUtil();

    private OSPlatform platform;

    private OSUtil() {
    }

    public static boolean isLinux() {
        return OS.indexOf("linux") >= 0;
    }

    public static boolean isMacOs() {
        return OS.indexOf("mac") >= 0 && OS.indexOf("os") > 0 && OS.indexOf("x") < 0;
    }

    public static boolean isWindows() {
        return OS.indexOf("windows") >= 0;
    }

    /**
     * 获取操作系统名字
     *
     * @return 操作系统名
     */
    public static OSPlatform get() {
        if (isLinux()) {
            instance.platform = OSPlatform.Linux;
        } else if (isMacOs()) {
            instance.platform = OSPlatform.Mac_OS;
        } else if (isWindows()) {
            instance.platform = OSPlatform.Windows;
        } else {
            instance.platform = OSPlatform.Others;
        }
        return instance.platform;
    }
}
